import { BasicColumn, FormSchema } from '/@/components/Table';
import { ref } from 'vue';
import dayjs from 'dayjs';
const dates = ref();
export const columns: BasicColumn[] = [
  {
    title: '房间号',
    dataIndex: 'room',
    align: 'center',
    width: 120,
  },
  {
    title: '线路',
    dataIndex: 'line',
    align: 'center',
    width: 120,
  },
  {
    title: '地址',
    dataIndex: 'addr',
    align: 'center',
    width: 120,
  },
  {
    title: '网关IP',
    dataIndex: 'ip',
    align: 'center',
    width: 120,
  },
  {
    title: '网关端口号',
    dataIndex: 'port',
    align: 'center',
    width: 120,
  },
  {
    title: '剩余电量',
    dataIndex: 'reskwh',
    align: 'center',
    width: 120,
  },
  {
    title: '查询时间',
    dataIndex: 'ctime',
    align: 'center',
    width: 180,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'room',
    label: '房间号',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'ip',
    label: '网关IP',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'rangeNumber',
    label: '剩余电量',
    component: 'JRangeNumber',
    colProps: { span: 6 },
  },
  {
    field: 'rtime',
    label: '查询时间',
    component: 'RangePicker',
    colProps: { span: 6 },
    componentProps: {
      showTime: true,
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      placeholder: ['请选择开始日期时间', '请选择结束日期时间'],
      allowClear: false,
      disabledDate: (current) => {
        if (!dates.value || (dates.value as any).length === 0) {
          return false;
        }
        const tooLate = dates.value[0] && current.diff(dates.value[0], 'month') > 6;
        const tooEarly = dates.value[1] && dayjs(dates.value[1]).diff(current, 'month') > 6;
        return tooEarly || tooLate;
      },
      onCalendarChange: (val) => {
        dates.value = val;
      },
    },
    defaultValue: [
      dayjs().subtract(30, 'day').startOf('day').format('YYYY-MM-DD HH:mm:ss'),
      dayjs().subtract(1, 'day').endOf('day').format('YYYY-MM-DD HH:mm:ss'),
    ],
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '房间剩余电量表ID',
    field: 'idx',
    component: 'Input',
  },
  {
    label: '房间号',
    field: 'room',
    component: 'Input',
  },
  {
    label: '线路',
    field: 'line',
    component: 'Input',
  },
  {
    label: '地址',
    field: 'addr',
    component: 'Input',
  },
  {
    label: '网关IP',
    field: 'ip',
    component: 'Input',
  },
  {
    label: '网关端口号',
    field: 'port',
    component: 'Input',
  },
  {
    label: '剩余电量',
    field: 'reskwh',
    component: 'Input',
  },
  {
    label: '查询时间',
    field: 'ctime',
    component: 'DatePicker',
    componentProps: {
      //日期格式化，页面上显示的值
      format: 'YYYY-MM-DD HH:mm:ss',
      //返回值格式化（绑定值的格式）
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      //是否显示今天按钮
      showToday: true,
      showTime: true,
    },
  },
];
